package com.fs.chatx.module.chat.service;
import com.fs.chatx.module.chat.enums.ModelProviderEnum;
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.EmbeddingClient;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionRequest;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
import io.github.pigmesh.ai.deepseek.core.embedding.Embedding;
import io.github.pigmesh.ai.deepseek.core.embedding.EmbeddingRequest;
import io.github.pigmesh.ai.deepseek.core.embedding.EmbeddingResponse;
import io.github.pigmesh.ai.deepseek.core.search.FreshnessEnums;
import io.github.pigmesh.ai.deepseek.core.search.SearchRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import java.util.List;

@Service
public class EmbeddingService
{
    @Autowired
    private EmbeddingClient embeddingClient;
    @Value("${embedding.model}")
    private String model;
    private final static Integer dimensions=512;

    public List<Float> embed(String prompt)
    {
        EmbeddingRequest builder = EmbeddingRequest.builder()
                .model(model)
                .input(prompt)
                .dimensions(dimensions)
                .build();
        EmbeddingResponse response= embeddingClient.embed(builder);
        return response.embedding();
    }

    public List<Embedding>  batchEmbed(List<String> input)
    {
        EmbeddingRequest builder = EmbeddingRequest.builder()
                .model(model)
                .input(input)
                .dimensions(dimensions)
               .build();
        EmbeddingResponse response= embeddingClient.embed(builder);
        return response.data();
    }

    //自定义embbiiding 模型
    public List<Float> embed(String prompt,ModelProviderEnum modelProvider)
    {
        EmbeddingRequest builder = EmbeddingRequest.builder()
                .input(new String[]{prompt})
                .dimensions(dimensions)
                .model(modelProvider.getModel().getModelName()).build();
        EmbeddingResponse response= embeddingClient.embed(builder);
        return response.embedding();
    }
    //自定义embbiiding 模型
    public List<Embedding> batchEmbed(List<String> input,ModelProviderEnum modelProvider)
    {
        EmbeddingRequest builder = EmbeddingRequest.builder()
                .input(input)
                .dimensions(dimensions)
                .model(modelProvider.getModel().getModelName()).build();
        EmbeddingResponse response= embeddingClient.embed(builder);
        return response.data();
    }


}
